<?php
/**
 * Created by PhpStorm.
 * User: wodrow
 * Date: 18-4-2
 * Time: 上午10:02
 */

namespace api\modules\chedai\models;


use yii\base\ErrorException;
use yii\base\Model;

class Login extends Model
{
    public $u_name;
    public $u_password;

    public function rules()
    {
        return [
            [['u_name', 'u_password'], 'required'],
            [['u_name', 'u_password'], 'string', 'max' => 50],
            ['u_password', 'ruleCheckUNameAndUPassword'],
        ];
    }

    public function ruleCheckUNameAndUPassword($attribute, $params)
    {
        if (!$this->getErrors()) {
            if (mb_strlen($this->$attribute, 'utf8')<6){
                $this->addError($attribute, '密码必须6位以上!');
            }
            if (!preg_match('/[0-9]/', $this->$attribute)||!preg_match('/[a-zA-Z]/', $this->$attribute)){
                $this->addError($attribute, '密码过于简单!(密码必须由大写字母小写字母和数字组成!)');
            }
        }
    }
}